package com.net.xpay.common.manager.impl.admin.rbac;

import com.google.common.base.Preconditions;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.admin.rbac.AdminUserMapper;
import com.net.xpay.common.domain.admin.rbac.AdminUser;
import com.net.xpay.common.manager.admin.rbac.AdminUserManager;
import com.net.xpay.common.model.admin.rbac.search.AdminUserSearchModel;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@ReadTransactional
public class AdminUserManagerImpl extends AbstractManager<AdminUser> implements AdminUserManager{

    @Autowired
    private AdminUserMapper mapper;


    @Override
    protected BasicMapper<Long, AdminUser> getMapper() {
        return mapper;
    }

    @Override
    public AdminUser findByMobile(String mobile) {
        Preconditions.checkArgument(Strings.isNotEmpty(mobile));
        AdminUser condition = new AdminUser();
        condition.setMobile(mobile);
        return getByCondition(condition);
    }

    @Override
    public List<AdminUser> search(AdminUserSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(AdminUserSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public AdminUser findById(Long adminUserId) {
        Preconditions.checkArgument(adminUserId != null);
        AdminUser condition = new AdminUser();
        condition.setId(adminUserId);
        return getByCondition(condition);
    }
}
